package cn.itcast.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

@Slf4j
@Configuration
public class FilterConfiguration {
    @Bean
    public GlobalFilter filter1() {
        return ((exchange, chain) -> {
            log.warn("前置1");
            return chain.filter(exchange).then(Mono.fromRunnable(() -> log.warn("后置1")));
        });
    }
    @Bean
    public GlobalFilter filter2() {
        return ((exchange, chain) -> {
            log.warn("前置2");
            return chain.filter(exchange).then(Mono.fromRunnable(() -> log.warn("后置2")));
        });
    }
    @Bean
    public GlobalFilter filter3(){
        return ((exchange, chain) -> {
            log.warn("前置3");
            return chain.filter(exchange).then(Mono.fromRunnable(()->log.warn("后置3")));
        });
    }
}
